// Copyright 2021 Guoyoko. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include "Widgets/SWidget.h"


/*
The unit formation of the tree structure is responsible for constructing 
	the attribute formation of the left and right standard structure
*/
class FSWDetailNode : public TSharedFromThis<FSWDetailNode>
{

public:
	FSWDetailNode(FName InNodeName, FName InNodeDisplayName, TSharedPtr<SWidget> InNodeWidget)
		:NodeName(InNodeName)
		,NodeDisplayName(InNodeDisplayName)
		,NodeWidget(InNodeWidget)
		//,ParentNode(nullptr)
	{
	}

	FSWDetailNode(TSharedPtr<FSWDetailNode> InSWDetailNode)
	{
		ParentNode = InSWDetailNode;
	}

	FSWDetailNode& AddChildNode(FName InNodeName, FName InNodeDisplayName = "NodeDisplayName", TSharedPtr<SWidget> InNodeWidget = nullptr)
	{
		TSharedPtr<FSWDetailNode> NewNode = MakeShareable(new FSWDetailNode(InNodeName, InNodeDisplayName, InNodeWidget));
		AddChildNodeInternal(NewNode);
		return *NewNode;
	}

	TSharedRef<class SWidget> GetNodeWidget()
	{
		return NodeWidget.ToSharedRef();
	}

	TArray<TSharedPtr<FSWDetailNode>> GetChildNodes()
	{
		return ChildNodes;
	}

private:

	void AddChildNodeInternal(const TSharedPtr<FSWDetailNode>& InNewNode)
	{
		ChildNodes.Add(InNewNode);
	}


public:

	bool bIsCategory = false;

	FName NodeName;

	//Set data item is default expanded 
	bool bDefaultExpanded = true;

private:

	FName NodeDisplayName;

	TArray<TSharedPtr<FSWDetailNode>> ChildNodes;

	TSharedPtr<FSWDetailNode> ParentNode;

	/*-> Custom UI*/
	TSharedPtr<class SWidget> NodeWidget;
};

